package org.xczy.boot.utils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

@Component
public class RedisUtil {

  private final RedisTemplate<String, Object> redisTemplate;

  @Autowired
  public RedisUtil(RedisTemplate<String, Object> redisTemplate) {
    this.redisTemplate = redisTemplate;
  }
  /**
   * 存储
   * @param key
   * @param value
   */
  public void setValue(String key, Object value) {
    redisTemplate.opsForValue().set(key, value);
  }

  /**
   * 获取
   * @param key
   * @return
   */
  public Object getValue(String key) {
    return redisTemplate.opsForValue().get(key);
  }

  /**
   * 删除
   * @param key
   * @return
   */
  public Boolean deleteKey(String key) {
    return redisTemplate.delete(key);
  }
}
